package com.jz;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Hasee on 2022-02-28.
 */
@RestController
@Slf4j
public class RabbitController {
    //mQ key value

    @RabbitListener(queuesToDeclare = @Queue("xiaolong"))
    public void testMQ(String message){
        System.out.println(message);
        log.info(message);
    }
    /*
    供应商--接收传过来的订单
     */

    @Autowired
    private AmqpTemplate amqpTemplate;
    @RabbitListener(queuesToDeclare = @Queue("XiaoLongOrder"))
    public void xiadan(OrderVo order){
        System.out.println(order.toString());
        log.info(order.toString());
//        log.info(message);
        //进行自己的逻辑操作，比如
        //1.根据单号验证当前订单是否已经执行过了
        //2.减库存
        //3.其他的逻辑处理
        MQResultVo mqResultVo =new MQResultVo();
        mqResultVo.setStatus(0);
        mqResultVo.setOrderCode("001");
        mqResultVo.setMessage("什么原因失败的");
        amqpTemplate.convertAndSend("mqResult",mqResultVo);
    }
}
